/*-----------------------------------------------------------------------------
	The contents of this file are subject to the Mozilla Public License
	Version 1.1 (the "License"); you may not use this file except in
	compliance with the License.You may obtain a copy of the License at
	http://www.mozilla.org/MPL/MPL-1.1.html
	
	Software distributed under the License is distributed on an "AS IS"
	basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
	License for the specific language governing rights and limitations
	under the License.
	
	The Original Code is Fever Framework code.
	
	The Initial Developer of the Original Code is Romain Ecarnot.
	Portions created by Initial Developer are Copyright (C) 2006
	the Initial Developer. All Rights Reserved.
	
	Contributor(s):
	
	Unless required by applicable law or agreed to in writing, software
	distributed under the License is distributed on an "AS IS" BASIS,
	WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
	See the License for the specific language governing permissions and
	limitations under the License.
-----------------------------------------------------------------------------*/

import com.bourre.events.EventType;

import fever.events.AbstractEvent;

/**
 * Event structure used with {@link fever.data.file.FileUploader} instance.
 *
 * @author Romain Ecarnot
 */
class fever.data.file.FileUploaderEvent extends AbstractEvent 
{
	//-------------------------------------------------------------------------
	// Events definition
	//-------------------------------------------------------------------------
	
	/** Triggered when user select file to upload. */
	public static var UPLOAD_SELECT : EventType = new EventType(" onUploadSelect" );
	
	/** Triggered when upload start. */
	public static var UPLOAD_START : EventType = new EventType(" onUploadStart" );
	
	/** Triggered during upload progress. */
	public static var UPLOAD_PROGRESS : EventType = new EventType(" onUploadProgress" );
	
	/** Trigerred when upload is finished. */
	public static var UPLOAD_COMPLETE : EventType = new EventType(" onUploadComplete" );
	
	/** Trigerred when error occured during upload process. */
	public static var UPLOAD_ERROR : EventType = new EventType(" onUploadError" );
	
	
	//-------------------------------------------------------------------------
	// Private properties
	//-------------------------------------------------------------------------
	
	private var _fileName : String;
	private var _fileSize : Number;
	private var _loadedBytes : Number;
	private var _percent : Number;
	private var _message : String;
	
	
	//-------------------------------------------------------------------------
	// Public API
	//-------------------------------------------------------------------------
	
	/**
	 * Constructor.
	 */
	public function FileUploaderEvent( type : EventType, name : String, size : Number, loaded : Number, message : String )
	{
		super( type );
		
		_fileName = name;
		_fileSize = size;
		_loadedBytes = loaded;
		_percent = Math.floor( ( _loadedBytes / _fileSize ) * 100 );
		_message = message;
	}
	
	/**
	 * Returns file name.
	 */
	public function getFileName() : String
	{
		return _fileName;	
	}
	
	/**
	 * Returns file size.
	 */
	public function getFileSize() : Number
	{
		return _fileSize;
	}
	
	/**
	 * Returns current loaded bytes.
	 */
	public function getLoadedBytes() : Number
	{
		return _loadedBytes;	
	}
	
	/**
	 * Returns loading percent.
	 */
	public function getPercent() : Number
	{
		return _percent;
	}
	
	/**
	 * Returns possible error message.
	 */
	public function getMessage() : String
	{
		return _message;	
	}
	
}